package com.jule.teenpatti.mail.config;

import com.jule.core.configuration.ConfigurableProcessor;
import com.jule.core.configuration.Property;
import com.jule.core.configuration.ThreadConfig;
import com.jule.core.database.DatabaseConfig;
import com.jule.core.jedis.JedisConfig;
import com.jule.core.utils.PropertiesUtils;
import lombok.extern.slf4j.Slf4j;

import java.net.InetSocketAddress;
import java.util.Properties;

/**
 * @author xujian 2017-12-14
 */
@Slf4j
public class Config {

    @Property(key = "mail.bind.ip", defaultValue = "0.0.0.0")
    public static String BIND_IP;

    @Property(key = "mail.bind.port", defaultValue = "59001")
    public static int BIND_PORT;

    @Property(key = "sub.game.ids", defaultValue = "0")
    public static String SUB_GAME_IDS;

    @Property(key = "notice.forward.port", defaultValue = "localhost:8501")
    public static InetSocketAddress NOTICE_FORWARD_PORT;

    @Property(key = "game.table.playerLimit", defaultValue = "50")
    public static int TABLE_PLAYER_LIMIT;

    @Property(key = "game.playerLimit", defaultValue = "3000")
    public static int PLAYER_LIMIT;

    @Property(key = "restful.ip", defaultValue = "127.0.0.1")
    public static  String REST_IP ;

    @Property(key = "restful.port", defaultValue = "8082")
    public static  int REST_PORT ;
    /**改变荷官的价格*/
    @Property(key = "change_croupier_price", defaultValue = "10")
    public static  int CHANGE_CROUPIER_PRICE ;

    /**日志服*/
    @Property(key = "app.log.url", defaultValue = "http://10.0.0.92:59001")
    public static String LOG_URL;

    @Property(key = "app.mode.test", defaultValue = "true")
    public static boolean MODE_TEST;
    @Property(key = "load.db.config.hour", defaultValue = "5")
    public static int loadDBConfigHour;

    /**
     * Load configs from files.
     */
    public static void load() {
        try {

            Properties[] props = PropertiesUtils.loadAllFromDirectory("./config/network");
            log.info("Loading: mail.properties");
            ConfigurableProcessor.process(Config.class, PropertiesUtils.loadAllFromDirectory("./config/network/"));
            log.info("Loading: redis.properties");
            ConfigurableProcessor.process(JedisConfig.class, props);
            log.info("Loading: database.properties");
            ConfigurableProcessor.process(DatabaseConfig.class, props);
            log.info("Loading: threadpool.properties");
            ConfigurableProcessor.process(ThreadConfig.class, props);
            log.info("Loading: signreach.properties");
//            ConfigurableProcessor.process(SignreachConfig.class, props);
        } catch (Exception e) {
            log.error("Can't load Game configuration", e);
            throw new Error("Can't load Game configuration", e);
        }
    }
}
